package com.manger.frame;

import com.manger.listener.ChromeCLickListener;
import com.manger.listener.JFrameWindowListener;
import com.manger.theme.CustomFLatLightLaf;
import com.manger.listener.ArrangeClickListener;
import com.manger.listener.AutoCaseClickListener;
import com.manger.utils.ChinaAreaTools;

import javax.swing.*;
import java.awt.*;
import java.net.URL;

public class AutoCaseFrame {

    public static JFrame frame;
    public static void init() throws Exception{

        frame = new JFrame();
        JPanel panel = new JPanel();

        panel.setBackground(Color.WHITE); // 设置为浅灰色
        frame.setTitle("自动立案");
        frame.setBackground(Color.BLUE);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        panel.setLayout(new FlowLayout(FlowLayout.CENTER,35, 20));
        frame.setResizable(false);
        frame.setVisible(true);
        frame.setContentPane(panel);

        JLabel arrangeLabel = createJLabel("整理案件",AutoCaseFrame.class.getClassLoader().getResource("image/icon-msys.png"));
        arrangeLabel.addMouseListener(new ArrangeClickListener());

        JLabel autoLabel = createJLabel("自动立案", AutoCaseFrame.class.getClassLoader().getResource("image/icon-mses.png"));
        autoLabel.addMouseListener(new AutoCaseClickListener());

        JLabel chromeLabel = createJLabel("浏览器", AutoCaseFrame.class.getClassLoader().getResource("image/icon-sqtj.png"));
        chromeLabel.addMouseListener(new ChromeCLickListener());

        frame.add(arrangeLabel);
        frame.add(autoLabel);
        frame.add(chromeLabel);
        frame.setSize(500, 250);
        frame.addWindowListener(new JFrameWindowListener());
        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
        frame.setLocation(dim.width/2-frame.getSize().width/2, dim.height/2-frame.getSize().height/2);

        /*Dialog dialog = new JDialog();
        dialog.setTitle("整理中");
        dialog.setModal(true);
        dialog.setLayout(new BorderLayout());
        dialog.setPreferredSize(new Dimension(250, 120));
        JPanel dialogPanel = new JPanel();
        dialogPanel.setBackground(new Color(255, 255, 255));
        dialogPanel.setLayout(new BorderLayout());
        dialog.setContentPane(dialogPanel);
        dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
        dialog.pack();
        dialog.setVisible(true);
        dialog.setLocation(dim.width/2-dialog.getSize().width/2, dim.height/2-dialog.getSize().height/2);*/

    }


    private static JLabel createJLabel(String text, URL url){
        JLabel jl = new JLabel(text);
        jl.setFont(new Font("Serif", Font.PLAIN, 20)); //
        jl.setHorizontalTextPosition(SwingConstants.CENTER);
        jl.setVerticalTextPosition(SwingConstants.BOTTOM);
        ImageIcon icon =new ImageIcon(Toolkit.getDefaultToolkit().getImage(url));
        Image icon1 = icon.getImage().getScaledInstance(120,120,Image.SCALE_DEFAULT);
        jl.setIcon(new ImageIcon(icon1));
        jl.setForeground(Color.BLACK);
        return jl;
    }
}
